/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.fsiebert.polytech.db.mediatheque.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Florent
 */
@Entity
@Table(name = "Livre")
@NamedQueries({
    @NamedQuery(name = "Livre.findAll", query = "SELECT l FROM Livre l"),
    @NamedQuery(name = "Livre.findByItemRef", query = "SELECT l FROM Livre l WHERE l.itemRef = :itemRef"),
    @NamedQuery(name = "Livre.findByTitre", query = "SELECT l FROM Livre l WHERE l.titre = :titre"),
    @NamedQuery(name = "Livre.findByCollection", query = "SELECT l FROM Livre l WHERE l.collection = :collection"),
    @NamedQuery(name = "Livre.findByAuteur", query = "SELECT l FROM Livre l WHERE l.auteur = :auteur")})
public class Livre implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ItemRef", nullable = false)
    private Integer itemRef;
    @Size(max = 255)
    @Column(name = "Titre", length = 255)
    private String titre;
    @Size(max = 50)
    @Column(name = "Collection", length = 50)
    private String collection;
    @Size(max = 50)
    @Column(name = "Auteur", length = 50)
    private String auteur;
    @JoinColumn(name = "ItemRef", referencedColumnName = "ItemRef", nullable = false, insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Item item;
    @JoinColumn(name = "Genre", referencedColumnName = "Genre")
    @ManyToOne
    private Genre genre;

    public Livre() {
    }

    public Livre(Integer itemRef) {
        this.itemRef = itemRef;
    }

    public Integer getItemRef() {
        return itemRef;
    }

    public void setItemRef(Integer itemRef) {
        this.itemRef = itemRef;
    }

    public String getTitre() {
        return titre;
    }

    public void setTitre(String titre) {
        this.titre = titre;
    }

    public String getCollection() {
        return collection;
    }

    public void setCollection(String collection) {
        this.collection = collection;
    }

    public String getAuteur() {
        return auteur;
    }

    public void setAuteur(String auteur) {
        this.auteur = auteur;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public Genre getGenre() {
        return genre;
    }

    public void setGenre(Genre genre) {
        this.genre = genre;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (itemRef != null ? itemRef.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Livre)) {
            return false;
        }
        Livre other = (Livre) object;
        if ((this.itemRef == null && other.itemRef != null) || (this.itemRef != null && !this.itemRef.equals(other.itemRef))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "eu.fsiebert.polytech.db.mediatheque.entity.Livre[ itemRef=" + itemRef + " ]";
    }
    
}
